﻿#ifndef MOBILEFILELISTVIEW_H
#define MOBILEFILELISTVIEW_H

#include <QListView>
#include <QStandardItemModel>
#include <QMouseEvent>
#include <QApplication>
#include <QMenu>
#include <QProcess>

#include "mobilefilelistdelegate.h"
#include "fileinfo.h"

class MobileFileListView : public QListView
{
    Q_OBJECT
public:
    explicit MobileFileListView(QWidget *parent = nullptr);
    ~MobileFileListView();

    //默认图标模式
    void setViewModeFlag(QListView::ViewMode mode, const QList<FileInfo> &listStruct);
    //设置每一个QListWidgetItem项的高度
    void setResize();
    //设置数据
    void setTimeLineViewData(const QList<FileInfo> &listStruct, QMap<QString, QStandardItem *> &itemMap);
    //获取点击索引
    int getRow(QPoint point);
    void selectRear(int row);
    void selectFront(int row);
    void selectExtent(int start, int end);
    //获取选择项文件名列表（不包括文件夹）
    void selectAllNames(QList<FileInfo> &fileList);
    //更新View的高度
    void setViewHeight();
    //界面缩放更新view高度
    void updateViewHeight();
public Q_SLOTS:
    //项单击
    void slotClicked(const QModelIndex &index);
    //项双击
    void slotDoubleClicked(const QModelIndex &index);
    //项右键
    void slotContextMenu(const QPoint &pos);
    //项右键打开
    void slotOpenTriggered();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
Q_SIGNALS:
    void signalSetResize(int height);
    void sigShowCopyButton();
    void sigHideCopyToComputerWidget();
    void sigSelectDataList(QList<FileInfo> &fileList);
    void sigMousePress(QMouseEvent *event);
    void sigShiftMousePress(QMouseEvent *event);
    void sigCtrlMousePress(QMouseEvent *event);
    void sigMouseRelease();
    void sigSelectAll();
    void sigMenuFilePath(QString filePath);

private:
    //设置图形模式高度
    void setWidgetIconItemHeight();
    //设置列表模式高度
    void setWidgetListItemHeight();
    //初始菜单
    void initMenuAction();
    //计算每一项的大小
    QString getSize(qint64 sizeByte);
    //区分是图片还是视频...
    //    QString m_currentListName;
    MobileFileListDelegate *m_listDelefate = nullptr;
    QStandardItemModel *m_listModel = nullptr;
    int m_height = 0;
    int m_width = 0;
    QMap<QString, QString> m_itemPath;
    QMenu *m_menu = nullptr;
    QAction *m_openAction = nullptr;
    QStringList m_loadIndexPath;
    int m_loadIndex = 0;
    QMap<QString, QStandardItem *> m_itemMap;

    QList<FileInfo> m_fileSelectList;
};

#endif // MOBILEFILELISTVIEW_H
